description: Implements the infrastructure of Slash Templates.
Allows for quick definition of slash commands based on templates.
Create a page with the #meta/template/slash
tag. The last component of the page name (after the /
if any) will be
used as the slash command’s name. The body of the page will be used as the text to be inserted, using Lua directives is
supported.
You can configure some specifics about your slash template in its template page’s frontmatter.
Optional keys:
description
: The description of the slash commandpriority
: To prioritize the slash command higher in the listonlyContexts
(advanced): To only make the slash command appear in certain (AST node based) contextsexceptContexts
(advanced): To make the slash command appear everywhere except in these (AST node) contexts${template.each(query from index.tag "meta/template/slash" where _.tag == "page", templates.fullPageItem)}
for st in query[
from index.tag "meta/template/slash"
where _.tag == "page"
](
from index.tag "meta/template/slash"
where _.tag == "page"
) do
local components = st.name:split("/")
local name = components[#components]
slashCommand.define {
name = name,
description = st.description,
priority = st.priority,
onlyContexts = st.onlyContexts,
exceptContexts = st.exceptContexts,
run = function()
local tpl = template.fromPage(st.name, st.raw)
editor.insertAtCursor(tpl(), false, true)
end
}
end